/*
 *接口编写处...
*如果接口需要做Action的权限验证，请在Action上使用属性
*如: [ApiActionPermission("OrderForm",Enums.ActionPermissionOptions.Search)]
 */
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using Mercury.Entity.DomainModels;
using Mercury.Order.IServices;
using Mercury.Core.Enums;
using Mercury.Core.Filters;
using Mercury.Core.Services;
using Microsoft.AspNetCore.Authorization;

namespace Mercury.Order.Controllers
{
    [Route("api/of")]
    public partial class OrderFormController
    {
        private readonly IOrderFormService _service;//访问业务代码
        private readonly IHttpContextAccessor _httpContextAccessor;

        [ActivatorUtilitiesConstructor]
        public OrderFormController(
            IOrderFormService service,
            IHttpContextAccessor httpContextAccessor
        )
        : base(service)
        {
            _service = service;
            _httpContextAccessor = httpContextAccessor;
        }


        [HttpGet, Route("syncPlannedOrder")]
        [ApiActionPermission(ActionPermissionOptions.Sync)]
        public async Task<IActionResult> SyncPlannedOrder()
        {
            return Json(await Service.SyncPlannedOrder());
        }

        [HttpGet, Route("computedPlannedOrder/{orderNo}")]
        [AllowAnonymous]
        [ApiActionPermission(ActionPermissionOptions.Compute)]
        public async Task<IActionResult> ComputedPlannedOrder(string orderNo)
        {
            var result = await Service.ComputedPlannedOrder(orderNo);
            Logger.Info(Core.Enums.LoggerType.Computed, orderNo, result.Status ? "Ok" : result.Message ?? "未知");
            return Json(result);
        }
    }
}
